#include "Buffer.h"

Buffer::Buffer() {
	this->tamanio=0;
	this->pointer=NULL;
	this->ListEspaciosLibres = new vector<unsigned int>();
} 

Buffer* Buffer::instancia = NULL;

Buffer::~Buffer() {
	this->ListEspaciosLibres->clear();
	delete this->ListEspaciosLibres;
	free(this->pointer);
}

vector<unsigned int>* Buffer::getListEspaciosLibres(){
	return this->ListEspaciosLibres;
}

Buffer * Buffer::getInstance() {
	if (!instancia)
		instancia = new Buffer();
	return (instancia);
}

void* Buffer::getPointer(){
	if (this->pointer==NULL)
		throw new NullPointerException();
	else
		return(pointer);
}

unsigned int Buffer::getTamanio(){
	return(tamanio);
}

void Buffer::setTamanio(unsigned int tam){
	if (this->tamanio==0){
		this->tamanio=tam;
		this->pointer= malloc(tam);
		if (this->pointer== NULL)
			throw new MemoryStorageException(StorageException::escritura);
	}
	else throw IllegalOperation();
}
